package com.top.art.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.top.art.entity.Ruler;
import com.top.art.mapper.RulerMapper;
import com.top.art.service.IRulerService;
import com.top.art.vo.CourseVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hjh
 * @since 2020-10-07
 */
@Service
public class RulerServiceImpl extends ServiceImpl<RulerMapper, Ruler> implements IRulerService {

    @Override
    public List<CourseVO> queryCourse(String province) {
        Ruler ruler = this.getOne(Wrappers.<Ruler>lambdaQuery().eq(Ruler::getProvince, province));
        if (ruler != null) {
            String scoreRule = ruler.getScoreRuler();
            if (StringUtils.isNotBlank(scoreRule)) {
                return new Gson().fromJson(scoreRule, new TypeToken<List<CourseVO>>() {}.getType());
            }
        }
        return new ArrayList<>();
    }
}
